package net.xdclass.config;

import feign.RequestInterceptor;
import lombok.extern.slf4j.Slf4j;
import net.xdclass.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.http.HttpServletRequest;

/**
 * @Classname InterceptorConfig
 * @Description TODO
 * @Date 2022/4/19 14:33
 * @Created by sunhao
 */
@Configuration
@Slf4j
public class InterceptorConfig implements WebMvcConfigurer {

  @Bean
  public LoginInterceptor loginInterceptor(){
    return new LoginInterceptor();
  }

  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(loginInterceptor())
               .addPathPatterns("/api/product/*/**","/api/banner/*/**","/api/cart/*/**")
        //排除不拦截的路径
        .excludePathPatterns("/api/product/*/page","/api/banner/*/list");
  }

}
